package collection;

import java.util.*;

public class SortStringDemo {
    public static void main(String[] args) {
        /*List<String> list = new ArrayList<>();
        list.add("tom");
        list.add("jack");
        list.add("rose");
        list.add("jerry");
        list.add("black");
        list.add("Kobe");
        System.out.println("list集合："+list);
        Collections.sort(list);//a:97,A:65,0:48
        System.out.println("升序排序list："+list);*/
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("里门司仪");
        list.add("三里雪");
        System.out.println("原始数据："+list);
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();//前-后，升序
            }
        });
        //Collections.sort(list, (o1,o2)-> o1.length()-o2.length());
        System.out.println("按字符串长度升序："+list);
    }
}
